<%@ page language="java" contentType="text/html;charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>first</title>
<link href="css/first.css" type=text/css rel=stylesheet>
<link href="css/private.css" type=text/css rel=stylesheet>
</head>
<body>
<table class="table table-bordered table-striped">
		<thead>
			<tr>
				<th style="width:50px;">编号</th>
				<th style="width:200px;">剧目</th>
				<th style="width:200px;">时间</th>
				<th style="width:200px;">地点</th>
				<th style="width:200px;">图片</th>
				<th style="width:200px;">备注</th>
				<th style="width:200px;">操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${dramas}" var="row">
				<tr>
					<td style="height:200px">${row.id}</td>
					<td style="height:200px">${row.drama_name}</td>
					<td style="height:200px">${row.time}</td>
					<td style="height:200px">${row.place}</td>
					<td style="height:200px"><img style="width:100px;height:auto" src="<%=basePath%>/${row.img}"></img></td>
		
					<td style="height:200px">${row.remark }</td>
					<td>
						<a style="width:50px;height: 30px;" class="change" href="#" onclick="changedis(${row.id})" >&nbsp;修改&nbsp;</a> 
						<a style="width:50px;height: 30px;" class="del" href="#" onclick="delDramas(${row.id})">&nbsp;删除&nbsp;</a>
					</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<div id="cov">
		<div id="hid">
			
			<div>
			<h3>修改剧目信息</h3>
			</div>
			<form action="" id="edit_form" enctype=multipart/form-data > 
			<input type="hidden" id="edit_id" name="id">
				 <label>剧目</label><input type="text" id="edit_drama_name" name="drama_name"/><br>
				 <label>时间</label><input type="text" id="edit_time" name="time"/><br>
				 <label>地点</label><input type="text" id="edit_place" name="place"/><br>
				 <label>剧照</label><input type="file" multiple="multiple" id="edit_img" name="imageFiles"/><br>
				 <label>备注</label><textarea type="text" id="edit_remark" name="remark"/><br>
				 <br>
		         <button type="button" class="btn" onclick="changehid()">关闭</button>
				 <button type="button" class="btn" onclick="updateDrama()">修改</button>
	        </form>
		</div>
	
	</div>
	
</body>
<script>
function changedis(id){
	document.getElementById("hid").style.display="block";
	document.getElementById("cov").style.display="block";
	$.ajax({
        type:"get",
        url:"<%=basePath%>first/getDramaById.action",
        data:{"id":id},
        success:function(data) {
        	$("#edit_id").val(data.id);
            $("#edit_drama_name").val(data.drama_name);
            $("#edit_time").val(data.time)
            $("#edit_place").val(data.place)
            $("#edit_imageFile").val(data.imageFile)
            $("#edit_remark").val(data.remark);  
        }
    });
	
}
function changehid(){
    document.getElementById("hid").style.display="none";
    document.getElementById("cov").style.display="none";
}
//删除剧目
function delDramas(id) {
    if(confirm('确定要删除该剧目吗?')) {
		$.post("<%=basePath%>first/delete.action",{"id":id},
			function(data){
	            if(data =="OK"){
	                alert("剧目删除成功！"); 
	                window.location.reload();
	            }else{
	                alert("剧目删除失败！");
	                window.location.reload();
	            }
        });
    }  
}
function updateDrama(){
	$.post("<%=basePath%>first/update.action",$("#edit_form").serialize(),function(data){
		if(data !="OK"){
			alert("剧目更新失败！");
			window.location.reload();
		}else{
			alert("剧目更新成功！");
			window.location.reload();
		}
	});
}
</script>
</html>